﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

public partial class Dotnet3_Extension_Methods_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var email = "leeyongjing@gmail.com";
        if (email.IsValidEmailAddress())
        {
            Response.Write("YJingLee提示:这是一个正确的邮件地址");
        }
        else
        {
            Response.Write("YJingLee提示:这是一个不正确的邮件地址");
        }
    }
}

public static class Extensions//静态类
{
    //  为string类扩展一个名字为IsValidEmailAddress的方法
    public static bool IsValidEmailAddress(this string s)
    //静态方法和this
    {
        Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
        return regex.IsMatch(s);
    }
}